package com.pan.admin.module.loanConfig.service.impl;

import com.pan.admin.common.utils.DateUtils;
import com.pan.admin.common.utils.SecurityUtils;
import com.pan.admin.module.loanConfig.dao.LoanFormFieldValueDao;
import com.pan.admin.module.loanConfig.entity.LoanFormFieldValue;
import com.pan.admin.module.loanConfig.service.LoanFormFieldValueService;
import com.pan.admin.module.loanProduct.dao.LoanProductPlanFieldDao;
import com.pan.admin.module.loanProduct.entity.LoanProductPlanField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 动态单字段值Service业务层处理
 *
 * @author ts
 * @date 2023-09-11
 */
@Service
public class LoanFormFieldValueServiceImpl implements LoanFormFieldValueService {

    @Autowired
    private LoanFormFieldValueDao loanFormFieldValueDao;

    @Autowired
    private LoanProductPlanFieldDao loanProductPlanFieldDao;


    /**
     * 根据ID获取列表动态单字段值
     *
     * @param id 动态单字段值主键
     * @return 动态单字段值
     */
    @Override
    public LoanFormFieldValue getById(Long id) {
        return loanFormFieldValueDao.getById(id);
    }

    /**
     * 查询动态单字段值列表
     *
     * @param loanFormFieldValue 动态单字段值
     * @return 动态单字段值
     */
    @Override
    public List<LoanFormFieldValue> list(LoanFormFieldValue loanFormFieldValue) {
        return loanFormFieldValueDao.list(loanFormFieldValue);
    }

    /**
     * 统计  机构表单关联数据
     *
     * @param loanFormField 动态单字段
     * @return 动态单字段
     */
    @Override
    public int countFormProduct(LoanProductPlanField loanFormField) {
        return loanProductPlanFieldDao.count(loanFormField);
    }

    /**
     * 新增动态单字段值
     *
     * @param loanFormFieldValue 动态单字段值
     * @return 结果
     */
    @Override
    public int insertLoanFormFieldValue(LoanFormFieldValue loanFormFieldValue) {
        loanFormFieldValue.setCreateTime(DateUtils.getNowDate());
        loanFormFieldValue.setStatus(1);
        loanFormFieldValue.setCreateBy(SecurityUtils.getUsername());
        return loanFormFieldValueDao.insertLoanFormFieldValue(loanFormFieldValue);
    }

    /**
     * 修改动态单字段值
     *
     * @param loanFormFieldValue 动态单字段值
     * @return 结果
     */
    @Override
    public int updateLoanFormFieldValue(LoanFormFieldValue loanFormFieldValue) {
        loanFormFieldValue.setUpdateTime(DateUtils.getNowDate());
        loanFormFieldValue.setUpdateBy(SecurityUtils.getUsername());
        return loanFormFieldValueDao.updateLoanFormFieldValue(loanFormFieldValue);
    }

}
